<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/yzr_style.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>药品入库</title>
</head>
<body>
<script type="text/javascript" src="<c:url value="/js/fusioncharts.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/fusioncharts.charts.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/fusioncharts.theme.fint.js"/>"></script>

<script type="text/javascript">

	/* document.getElementById("yzr-import-div").src="yzr-test-tu.jsp"; */

	$(function(){
		
		//获取当前登录用户的id
		var  instockRcr_staffId = $("#tontyiStaffId").html();
		
		var dingdanId_instock = undefined;
		
		//打开窗口
		$("#yzr-instock-btn").linkbutton({
			onClick: function(){
				$("#yzr-selectOrder-instock-win").window("open");
				$("#tb-purchorder-instock").datagrid({
		    		url: 'queryAllOrByNoInst_yzr', 
		    		method: 'get'
		    	});
				$("#yzr-instock-staff").combogrid("setValue",instockRcr_staffId);
			}
		});
		
		
		//选择订单
		$("#yzr-ok-instock-btn").linkbutton({onClick: function(){
			var rows = $("#tb-purchorder-instock").datagrid("getSelections");
			if(rows.length == 1){
				var dingdanId_instock = rows[0].purchOrderId;
				$("#yzr-selectOrder-instock-win").window("close");
				$("#yzr-instock-input").textbox("setValue",dingdanId_instock);
				var dingdanId_instock = undefined;
			}else{
				$.messager.alert("提示", "您还没有选择记录！");
			}
		}});
		
		
		
		//模糊查询
		$('#yzr-selOrder-instock-search').searchbox({
		    searcher:function(value,name){
		    	if(value == ''){
		    		$.messager.alert("提示", "请输入查询条件！");
		    	}else{
		    		$("#tb-purchorder-instock").datagrid({	    		
			    		url:'queryByIf',
			    		method: 'post', 
			    		queryParams: {
			    			value: value,
			    			name: name
			    	}});
			    	$('#yzr-selOrder-search').searchbox('setValue', '');
		    	}	    			    	
		    }		    
		}); 
		
		//显示全部
		$("#yzr-selOrder-instock-reload").linkbutton({onClick:function(){
			$("#tb-purchorder-instock").datagrid({
	    		url: 'queryAllOrByNoInst_yzr', 
	    		method: 'get'
	    	});
		}});
		
		//根据日期段查询
		$("#yzr-ok-instock-search").linkbutton({onClick:function(){
			
			var start = $("#yzr-selOrder-instock-startDate").datebox("getValue");
			var end = $("#yzr-selOrder-instock-endDate").datebox("getValue");
			
			if(start == '' || end == ''){
				$.messager.alert("提示", "请选择日期！");
			}else{
				$("#tb-purchorder-instock").datagrid({
		    		url: 'queryByJiaoHuoDate', 
		    		method: 'post',
		    		queryParams: {
		    			startDate: start,
		    			endDate: end
		    	}});
				$('#yzr-selOrder-instock-startDate').datebox('setValue', '');
				$('#yzr-selOrder-instock-endDate').datebox('setValue', '');
			}			
		}});
		
		//根据采购id查找出采购详情
		$("#yzr-instock-input").textbox({
			onChange: function(newValue, oldValue){
				//$.messager.alert("提示", "请勾选合格的药品！");
				 $("#yzr-instockOrderDet-dg").datagrid({
					url:'queryOrderByOrderId',
					width: '100%',
					queryParams:{
						page:1, 
		    			rows:100,
		    			orderId: newValue
					}
				});
			}
		});
		
		// 提交数据
		$("#yzr-instock-submit").linkbutton({onClick: function(){		
			var rows = $("#yzr-instockOrderDet-dg").datagrid("getRows");
			var arr = [];
			for(var i = 0; i < rows.length; i ++){
				arr.push(rows[i].purchOrderDetId);
			}
					
			var orderId = $("#yzr-instock-input").textbox("getValue");
			var kind = $("#yzr_instock_kind").combobox("getValue");
			var store = $("#yzr-instock-store").combogrid("getValue");
			
			var staffId = $("#yzr-instock-staff").combogrid("getValue");
			var checkDate = $("#yzr-instock-date").datebox("getValue");
			
			$('#yzr_instock_form').form('submit', {
				url: 'ruKuMedYzr',
				queryParams:{
					list: arr,
					orderId: orderId,
					kind: kind,
					store: store,
					staffId: staffId,
					checkDate: checkDate
				},
			    onSubmit: function(){
			    	return $(this).form("validate");
			    },
			    success:function(data){
			    	/* var json = eval("(" + data + ")");
					$.messager.alert("提示", json.reason); */
					$.messager.alert('提示', "入库成功！");
					$(this).form("clear");
					$('#yzr-instockOrderDet-dg').datagrid('loadData', { total: 0, rows: [] }); 
			    }
			});
		}});
		

		$('#yzr-instock-tabs').tabs({
		    onSelect:function(title,index){
		        
		        if(title == '统计图表'){
		        	$("#yzr-display-none").css("display","none");
		        }else if(title == '查看详情'){
		        	$("#yzr-display-none").css("display","none");
		        }else if(title == '入库明细'){
		        	$("#yzr-display-none").show();
		        }
		    }
		});
		
		//查看详情
		$("#yzr-intock-detail-more").linkbutton({onClick: function(){
			var rows = $("#yzr-intock-detail-dg").datagrid("getSelections");
			if(rows.length == 1){
				var instockId = rows[0].medInstockId;
				$('#yzr-intock-detail-window').window("open");
				
				$.getJSON("queryInstockByIdYzr", {"instockId": instockId}, function(data){
					//medInstockId,medInstockBrokerage,medInstockKind,medInstockPurchOrderId,medInstockStoreName,medInstockTime
					$("#yzr-intock-detail-rkbh").linkbutton({text: data.medInstockId});
					$("#yzr-intock-detail-rklx").linkbutton({text: data.medInstockKind});
					$("#yzr-intock-detail-rkdd").linkbutton({text: data.medInstockPurchOrderId});
					$("#yzr-intock-detail-rkr").linkbutton({text: data.staffName});
					$("#yzr-intock-detail-ck").linkbutton({text: data.storeName});
					$("#yzr-intock-detail-rksj").linkbutton({text: data.medInstockTime});
					
				});	
				
				 //根据id查看详情	
				 $("#yzr-intockMed-detail-dg").datagrid({
					url:'queryInstockDetByIdYzr',
					width: '100%',
					queryParams:{
						instockId: instockId
					}
				});
			}else{
				$.messager.alert("提示", "请选择一条记录!");
			}
		}});
		
		//刷新
		$("#yzr-intock-detail-reload").linkbutton({onClick: function(){
			$("#yzr-intock-detail-dg").datagrid({
				url:'queryAllInstockYzr',			
			});
		}});
	});
</script>
<script type="text/javascript">
	 var yzr_count1= new FusionCharts({
		"type" : "column3d",
		"renderAt" : "show_yzr_countInstock",
		"width" : "60%",
		"height" : "200%",
		"dataFormat" : "xmlurl",
		"dataSource" : "rukuCountYzr"

	});
	 yzr_count1.render();
</script>


	<!-- 入库数据 -->
	<div id="yzr-display-none">
	<form id="yzr_instock_form" method="post" style="background:#ECF3FF;padding:20px;">
		<table style="width:100%;">
			<tr>
				<td style="width:37%;">
					<input id="yzr-instock-input" class="easyui-textbox" data-options="required:true,width: '75%',labelAlign:'right',label:'采购单'"/>
					<a id="yzr-instock-btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:22%;">查找</a>
				</td>
				<td style="width:30%;">
					<select id="yzr_instock_kind" class="easyui-combobox" data-options="
					   		label: '入库类型',
							labelAlign:'right',
							required:true,
							width: '95%',
							panelWidth: '150',
							panelHeight: 'auto'">
					    
					    <option value="采购入库">采购入库</option>
					    <option value="调拨入库">调拨入库</option>
					</select>
				</td>
				<td style="width:33%;">
					<div style="margin-left:-30px;">
						<select class="easyui-combogrid" id="yzr-instock-store" style="border:1px solid blue;"
							data-options="
								label: '仓库',
								labelAlign:'right',
								required:true,
								width: '80%',
								panelWidth: '290',
								panelHeight: 'auto',
								url: 'queryAllStorehouse',
								pagination: true,
								pageSize: 8,
								pageList: [8, 16, 24, 32],
								idField: 'storeId',
								textField: 'storeName',
								columns: [[				
									{field:'storeName',title:'仓库名',width:100},
									{field:'storeKind',title:'类型',width:85},
									{field:'storeAddress',title:'地址',width:100}
								]]
						"></select>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<select class="easyui-combogrid" id="yzr-instock-staff"
						data-options="
							label: '入库人',
							labelAlign:'right',
							readonly:true,
							required:true,
							width: '95%',
							panelWidth: '290',
							panelHeight: 'auto',
							url: 'queryAllStaff',
							pagination: true,
							pageSize: 8,
							pageList: [8, 16, 24, 32],
							idField: 'staffNo',
							textField: 'staffName',
							columns: [[
								{field:'staffName',title:'姓名',width:100},
								{field:'departmentName',title:'部门',width:100},
								{field:'postName',title:'职务',width:85}
							]]
					"></select>
				</td>
				<td>
					<input class="easyui-datebox" id="yzr-instock-date" data-options="width:'95%',required:true,labelAlign:'right',label:'入库日期'">
				</td>
			</tr>
		</table>
	</form>	
	</div>
						

	<!-- 订单明细 -->
	<div style="margin: 20px;">
		<div id="yzr-instock-tabs" class="easyui-tabs" style="width:100%; margin-top:10px;" 
			data-options="plain:true,narrow:true,tabHeight:'150%',tabWidth:'100%'">
			
			<!-- tab1 -->
			<div title="入库明细" style="padding:10px;">
				<table id="yzr-instockOrderDet-dg" class="easyui-datagrid" 
						data-options="
							iconCls: 'icon-edit',
							toolbar: '#yzr-instockOrderDet-toolbar',								
							width: '100%',
							height: '300px'
							">
						<thead>
							<tr>	
								<th data-options="field:'purchOrderDetId',width:'19%',align:'center'">订单明细编号</th>			
								<th data-options="field:'orderDetMedName',width:'19%',align:'center'">药品名称</th>
								<th data-options="field:'orderDetGuige',width:'10%',align:'center'">规格</th>
								<th data-options="field:'orderDetMedUnit',width:'10%',align:'center'">单位</th>
								<th data-options="field:'orderDetPrice',width:'10%',align:'center'">单价</th>
								<th data-options="field:'orderDetNumber',width:'10%',align:'center'">数量</th>
								<th data-options="field:'orderDetMoney',width:'10%',align:'center'">金额</th>
								<th data-options="field:'supName',width:'13%',align:'center'">供应商</th>
								<!-- <th data-options="field:'XXX',width:'2%',idField:'purchOrderDetId',checkbox:true">是否合格</th> -->
							</tr>
						</thead>
				 </table>
				 <!-- 确认按钮 -->
				<div id="yzr-instockOrderDet-toolbar">
					<a id="yzr-instock-submit" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-ok'">入库</a>	
				</div>
			</div>
			
			<!-- tab2 -->
			<div id="yzr-import-div" title="统计图表" style="padding:10px;">
				
				<div id="show_yzr_countInstock" style="width:100%;height:150%;"></div>
					
					
			</div>	
			
			<!-- tab3 -->
			<div  title="查看详情" style="padding:10px;">
				<table id="yzr-intock-detail-dg" class="easyui-datagrid" 
					data-options="
						url: 'queryAllInstockYzr',
						iconCls: 'icon-edit',	
						pagination: true,
						singleSelect: true,
						toolbar: '#yzr-intock-detail-tb',
						pageSize: 16,
						pageList: [16, 32, 48, 54],						
						width: '100%',
						height: '400px'
						">
					<thead>
						<tr>
						<!-- 入库编号，入库类型（采购入库，调拨入库），入库人，仓库编号，入库的时间，采购订单号	 
						//medInstockId,medInstockBrokerage,medInstockKind,medInstockPurchOrderId,medInstockStoreName,medInstockTime-->	
							<th data-options="field:'XXX',width:'20%',checkbox:true">入库编号</th>
							<th data-options="field:'medInstockId',width:'20%',align:'center'">入库编号</th>				
							<th data-options="field:'medInstockKind',width:'16%',align:'center'">入库类型</th>
							<th data-options="field:'medInstockPurchOrderId',width:'20%',align:'center'">入库订单</th>
							<th data-options="field:'staffName',width:'14%',align:'center'">入库人</th>
							<th data-options="field:'storeName',width:'13%',align:'center'">仓库</th>
							<th data-options="field:'medInstockTime',width:'14%',align:'center'">入库时间</th>														
						</tr>
					</thead>
				</table>
				<div id="yzr-intock-detail-tb">
					<a id="yzr-intock-detail-more" class="easyui-linkbutton" data-options="iconCls:'icon-more',plain:true">查看详情</a>
					<a id="yzr-intock-detail-reload" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>					
				</div> 
			</div>							
		</div>						
	</div>

	
	
	<!--查看详情窗口 -->
	<div id="yzr-intock-detail-window" class="easyui-window" title="查看入库详情" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:70%;height:70%;">		
		<div class="easyui-layout" style="padding:0px;" data-options="fit:true">			
			<div data-options="region:'center'" style="padding:5px;border-top:none;border-left:none;border-right:none;">	
				
				<form id="yzr_intock-detail_form" method="post" style="margin:10px;width:98%;">
					<table width="98%" style="margin:10px;">
						<tr>
							<td>入库编号:<a id="yzr-intock-detail-rkbh" name="purchId" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>入库类型:<a id="yzr-intock-detail-rklx" name="purchTitle" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>入库订单:<a id="yzr-intock-detail-rkdd" name="staffName" class="easyui-linkbutton" data-options="plain:true"></a></td>
							
						</tr>
						<tr>
							<td>入库人:<a id="yzr-intock-detail-rkr" name="staffNameSp" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>仓库:<a id="yzr-intock-detail-ck" name="purchAutditState" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>入库时间:<a id="yzr-intock-detail-rksj" name="purchAutditTime" class="easyui-linkbutton" data-options="plain:true"></a></td>
							
						</tr>
					</table>
						
					<div style="margin: 10px;">
						<div id="yzr-purchDet-tabs" class="easyui-tabs" style="width:98%; margin-top:10px;" 
							data-options="plain:true,narrow:true">
							
							<div title="入库药品明细" style="padding:10px;">
								<table id="yzr-intockMed-detail-dg" class="easyui-datagrid"  style="margin-left:10px"
										data-options="
											iconCls: 'icon-edit',
											singleSelect: true,
											align: 'center',										
											width: '98%'
											">
										<thead>
											<tr>	<!--入库详情编号，入库编号，药品编号，药品名称，批号，规格，单价，数量，金额
											//medInstockDetId,medInstockDeGuige,medInstockDetBatchnumber,medInstockDetMedId,
											medInstockDetMedName,medInstockDetMoney,medInstockDetNumber,medInstockDetPrice,medRukuId,  -->
												<th data-options="field:'medInstockDetId',width:'20%',align:'center'">入库详情编号</th>		
												<th data-options="field:'medInstockDetMedName',width:'20%',align:'center'">药品名称</th>
												<th data-options="field:'medInstockDetBatchnumber',width:'15%',align:'center'">批号</th>
												<th data-options="field:'medInstockDeGuige',width:'12%',align:'center'">规格</th>
												<th data-options="field:'medInstockDetPrice',width:'12%',align:'center'">单价</th>
												<th data-options="field:'medInstockDetNumber',width:'12%',align:'center'">数量</th>
												<th data-options="field:'medInstockDetMoney',width:'11%',align:'center'">金额</th>
											</tr>
										</thead>
								 </table>
							</div>						
						</div>				
					</div>
				</form>								
			</div>
					
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#yzr-intock-detail-window').window('close');" onclick="">取消</a>
			</div>			
		</div>
	</div>
	
	
	
	
	
	
	<!-- 选择订单窗口 -->
	<div id="yzr-selectOrder-instock-win" class="easyui-window" title="选择采购订单" style="width:900px;height:350px;" data-options="closable:true,closed:true,collapsible:false,minimizable:false,maximizable:false">
		<table id="tb-purchorder-instock" class="easyui-datagrid" 
			data-options="
				url:'queryAllOrder',				
				fit:true,
				pagination: true,
				pageSize: 8,
				pageList: [8, 16, 24, 32],
				rownumbers: false,
				toolbar: '#yzr-toolbar-instock',
				border:false,
				singleSelect:true
				">
			<thead>
				<tr>	
					<th data-options="field:'purchOrderId',width:'16%',align:'center'">订单编号</th>				
					<th data-options="field:'purchPurchId',width:'17%',align:'center'">计划单号</th>
					<th data-options="field:'staffName',width:'9%',align:'center'">采购人</th>											
					<th data-options="field:'purchOrderDate',width:'11%',
										formatter:function(value){
						                          var date = new Date(value);  
						                          return date.toLocaleDateString();},align:'center'"
					>订货日期</th>				
					<th data-options="field:'purchJiaohuoDate',width:'11%',
										formatter:function(value){
						                          var date = new Date(value);  
						                          return date.toLocaleDateString();},align:'center'"
					>交货日期</th>
					<!-- <th data-options="field:'purchJiaohuoAddress',width:'10%',align:'center'">交货地点</th> -->
					<th data-options="field:'purchOrderNumber',width:'9%',align:'center'">订货项数</th>	
					<th data-options="field:'purchOrderMoney',width:'9%',align:'center'">订单金额</th>
					<th data-options="field:'purchYanshouState',width:'11%',align:'center',styler: function(value,row,index){
										if (value == '未验收'){
											return 'color:red;';											
										}
					}">验收状态</th>
					<th data-options="field:'purchInstockState',width:'9%',align:'center'">是否入库</th>				
				</tr>
			</thead>
		</table>				    
	    
	    <!-- 工具栏 -->
	    <div id="yzr-toolbar-instock">
	    	<input id="yzr-selOrder-instock-search" class="easyui-searchbox" data-options="menu: '#yzr-serch-instock', width: 250, prompt: '请输入关键字'"/>    	
	    	<input id="yzr-selOrder-instock-startDate" class="easyui-datebox" data-options="label:'交货日期',labelAlign:'right', width: 200" /> -
	    	<input id="yzr-selOrder-instock-endDate" class="easyui-datebox" data-options="width: 110"/>
	    	<a id="yzr-ok-instock-search" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
	    	<a id="yzr-ok-instock-btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" style="margin-left:110px;">确定</a>
	    	<a id="yzr-selOrder-instock-reload" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
	    </div>
	    	    
	    <!-- 搜索框 -->
	    <div id="yzr-serch-instock" style="width:120px">
	    	<div data-options="name:'orderId'">订单编号</div>
		    <div data-options="name:'name'">采购人</div>
		    <div data-options="name:'checkState'">验收状态</div>
		    <div data-options="name:'rukuState'">是否入库</div>
		</div>		
	</div>	
</body>
</html>